<template>
  <div class='edit-gender'>
    <van-picker
      title="修改性别"
      show-toolbar
      :columns="columns"
      :default-index="this.localGender"
      @confirm="onConfirm"
      @cancel="$emit('closeEditGenderShow')"
      @change="onGenderChange"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
import { Toast } from 'vant'

export default {
  name: 'editGender',
  components: {},
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女'],
      localGender: this.value
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onGenderChange (picker, value, index) {
      this.localGender = index
    },
    async onConfirm () {
      Toast.loading({
        message: '请稍等...',
        forbidClick: true
      })
      await updateUserProfile({
        gender: this.localGender
      })
      this.$emit('closeEditGenderShow')
      this.$emit('input', this.localGender)
      Toast.success('更改成功')
    }
  }
}
</script>
<style lang='less' scoped></style>
